﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pokerServer.ProtHandlers;
using ProtHandlers;
using ConnectionControl;
using pokerServer.ProtHandlers.Concrete;
using pokerServer.ProtHandlers.Interfaces;
using pokerServer.ProtHandlers.Factories;
namespace pokerServer.ProtHandlers
{

	public enum States
	{
		AUTH,

		ACTION,
		SEATDOWNTABLE,
		SEATUPTABLE,
		JOINTABLE,
		PARTTABLE,

		REQUEST,
		REGISTER,
		QUIT,
		NOTHING
	}

	class HandlerFact :IHandler
	{
		//Factory Pattern
		IProtHandle handler;
		States e = States.NOTHING;
		RequestFact rf = new RequestFact();

		public IProtHandle getHandler(String[] s,ConnectionManag cm,ClientConnection cc)
		{
			//Strategy Pattern
			switch (s[0])
			{
				case "AUTH":
					e = States.AUTH;
					handler = new authProtHandle(s,cc);
					break;
				case "REGISTER":
					e = States.REGISTER;
					handler = new regProtHandle(s,cc);
					break;
				case "ACTION":
					e = States.ACTION;
					handler = new tableV2ProtHandle(cm, cc, cc.myPlayer, s);
					break;
				case "SEATDOWNTABLE":
					e = States.SEATDOWNTABLE;
					handler = new tableV2ProtHandle(cm, cc, cc.myPlayer, s);
					break;
				case "SEATUPTABLE":
					e = States.SEATUPTABLE;
					handler = new tableV2ProtHandle(cm, cc, cc.myPlayer, s);
					break;
				case "JOINTABLE":
					e = States.JOINTABLE;
					handler = new tableV2ProtHandle(cm, cc, cc.myPlayer, s);
					break;
				case "PARTTABLE":
					e = States.PARTTABLE;
					handler = new tableV2ProtHandle(cm, cc, cc.myPlayer, s);
					break;

				case "REQUEST":
					e = States.REQUEST;
					handler = rf.getHandler(s, cm, cc);
					break;
				default:
					e = States.QUIT;
					handler = new quitHandler(s);
					break;				
					

			}
			return handler;

		}
		public States getState()
		{
			return e;
		}


	
	}
}
